/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package FrameSekretariat;

import FrameAdmin.Admintambahuser;
import Model.PengendaliUser;
import Model.UserPenerima;
import Model.UserSekre;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.*;

/**
 *
 * @author User
 */
public class Sekretambahuser extends JFrame {

    private JLabel idsekre, namasekre;
    private JTextField textidsekre, textnamasekre;
    private JButton buttonOk, buttonCancel;

    public Sekretambahuser() {
        this.setTitle("User Penerima");
        this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        this.setBounds(400, 300, 320, 170);
        this.setLayout(null);

        idsekre = new JLabel("User ID");
        idsekre.setBounds(20, 20, 65, 25);
        this.add(idsekre);

        namasekre = new JLabel("Nama User");
        namasekre.setBounds(20, 50, 65, 25);
        this.add(namasekre);

        textidsekre = new JTextField();
        textidsekre.setBounds(95, 20, 190, 25);
        this.add(textidsekre);

        textnamasekre = new JTextField();
        textnamasekre.setBounds(95, 50, 190, 25);
        this.add(textnamasekre);

        buttonOk = new JButton("ADD");
        buttonOk.setBounds(55, 85, 80, 30);
        this.add(buttonOk);
        buttonOk.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                if (textidsekre.getText().equals("")) {
                    JOptionPane.showMessageDialog(null, "Anda belum memasukan user ID");
                } else {
                    UserPenerima penerima = new UserPenerima();
                    try {
                        penerima.setIdUserPenerima(textidsekre.getText());
                        penerima.setNamaUserPenerima(textnamasekre.getText());
                        PengendaliUser.tambahUserPenerima(penerima);
                        try {
                            PengendaliUser.tambahTabelUserPenerima(penerima);
                            JOptionPane.showMessageDialog(null, "User ID Tersimpan");
                            textidsekre.setText(null);
                            textnamasekre.setText(null);
                        } catch (SQLException ex) {
                            JOptionPane.showMessageDialog(null, "ID atau Nama yang anda masukan sudah ada");
                        }
                    } catch (Exception ex) {
                        JOptionPane.showMessageDialog(null, ex.getMessage());
                    }
                }
            }
        });

        buttonCancel = new JButton("CANCEL");
        buttonCancel.setBounds(170, 85, 80, 30);
        this.add(buttonCancel);
        buttonCancel.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                setVisible(false);
            }
        });
    }
}
